package com.mes.common.usermanagement;
/*
 * Created on 2003-6-11
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */


/**
 * @author Administrator
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import java.util.StringTokenizer;

import org.apache.log4j.Logger;

public class Environment extends Properties
{
private static Logger logger=Logger.getLogger(Environment.class.getName());
    public Environment()
        throws IOException
    {
        Process p = System.getProperty("os.name").toUpperCase().indexOf("WIN") != -1 ? Runtime.getRuntime().exec("cmd /Cset") : Runtime.getRuntime().exec("env");
//        logger.info("+++++++++++the p.getInputStream is++++++++ "+p.getInputStream().);
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
//        logger.info("+++++++++++the BufferdReader br is+++++++++++++ "+br);
        int i=0;
        for(String line = ""; (line = br.readLine()) != null;)
        {
            StringTokenizer st = new StringTokenizer(line, "=");
//            logger.info(i+"the +++++++StringTokenizer st is +++++++"+st);
            String n = st.nextToken();
//            logger.info(i+"the +++++++String n is +++++++"+n);
            String v;
            int m=0;
            for(v = ""; st.hasMoreTokens(); v = v + st.nextToken() + (st.hasMoreTokens() ? "=" : ""));{
//            	logger.info(i+m+"++++++the string v at beginning is+++++ "+v);
            	setProperty(n.toLowerCase(), v);
//            	logger.info(i+m+"+++++++the string v at ending is++++++ "+v);
            	m++;
            }

            i++;
        }

    }

    public String getProperty(String key)
    {
        if(key != null)
            return super.getProperty(key.toLowerCase());
        else
            return "";
    }
}
